//include headers
#include <avr/io.h>
#include <avr/interrupt.h>


#define F_CPU 8000000

#include <util/delay.h>


//pwm frequency = 100hz
//resolution = 8 bits (256)
//interrupt frequency = 25600


	/////////////////
	/// Variables ///
	/////////////////
	
	uint8_t counter = 0;
	uint8_t i;
	uint8_t output;
	
	uint8_t values[8] = {0, 32, 64, 96, 128, 160, 192, 224};


int main(void) {
	//////////////////////
	/// Initialization ///
	//////////////////////
	
	//Setup outputs
	DDRB = 255; //PORTB = OUTPUT
	
	//Configure timer
	TCCR1B |= (1 << WGM12); //CTC Mode
	OCR1A = 500; //Set compare value
	TCCR1B |= (1 << CS00); //no prescaler
	
	//Configure interrupts
	TIMSK |= (1 << OCIE1A); //Enable CTC interrupt
	sei(); //enable global interrupt
	


		

	for(;;) {
			
	}

ISR(TIMER1_COMPA_vect) {
	//reset output variable
	output = 0;
	
	//chek to see if each output is greater than i, if so turn on that led
	for (i = 0; i < 8; i++) {
		//if value of led i is greater than counter turn it on
		output &= ~(1 << i);
		if (values[i] > counter)
			output |= (1 << i);
	}
	
	PORTB = ~output;
	
	//increment counter for comparison to brightness value
	counter++;
}
